<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <!--    <script src="/static/js/framework-ui.js"></script>-->
    <!--    <script src="/static/js/framework-clientdata.js"></script>-->

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>


    <!--    配置select多选相关-->
    <!--    <script src="/static/layui/dist/xm-select.js"></script>-->


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}

    <script src="/static/build/tracking-min.js"></script>
    <script src="/static/build/data/face-min.js"></script>
    <script src="/static/build/data/eye-min.js"></script>
    <script src="/static/build/data/mouth-min.js"></script>
</head>
<body>
<style>
    html, body {
        background-color: #FFF !important;
    }

    .modal-body {
        background-color: #fff;
        padding: 15px
    }

    .page-header {
        margin-top: 15px !important;
    }

    .geographic input {
        width: 100px !important;
        float: left;
        margin-right: 15px;
    }

    .new-content {
        padding: 15px 0px
    }

    .config_img {
        width: 45px;
        height: 45px;
        margin-top: 15px;
    }
    .form-horizontal{padding-bottom:80px;}
</style>

<div class="modal-body">


    <div class="modal-header">

        <div class="assistant_header">
            <button type="button" class="close" data-dismiss="modal" close="true">
                <span aria-hidden="true">×</span>
            </button>
            <h4 class="modal-title">
                <span class="fa fa-legal"></span>添加新闻
            </h4>
        </div>
    </div>

    <div class="new-content">
        <form class="form-horizontal layui-form">


            <div class="form-group">
                <label class="col-sm-1 control-label newtitle">所属分类:</label>
                <div class="col-sm-3">
                    <select name="classify_id" lay-verify="classify_id"  lay-filter="classify_id" lay-search="" class="select">
                        <option value="0">选择分类</option>
                        {volist name="classify" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['classify_id'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="form-group js_photos">

                <label class="col-sm-1 control-label newtitle">*标题:</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" name="title" placeholder="标题" value="{$detail.title}">
                </div>



            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label newtitle">推荐:</label>
                <div class="col-sm-8" style="margin-top:10px">
                    <input type="checkbox" name="hot[]" value="0" lay-skin="primary" title="其他" {if condition="in_array(0,$hot)"} checked {/if} >
                    <input type="checkbox" name="hot[]" value="1" lay-skin="primary" title="首页推荐" {if condition="in_array(1,$hot)"} checked {/if}>
                    <input type="checkbox" name="hot[]" value="2" lay-skin="primary" title="列表页推荐" {if condition="in_array(2,$hot)"} checked {/if} >
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-1 control-label">缩略图:</label>
                <div class="col-sm-3">
                    <div class="input-group ">
                        <input type="text" id="thumb" name="thumb" value="{$detail.thumb}" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                        <button class="btn btn-default" id="upload" type="button" data-original-title="" title="">选择图片</button>
                    </span>
                    </div>
                    {if condition="$detail['thumb'] eq ''"}
                    <img class="config_img thumb" src="/static/images/nopic-107.png" >
                    {else/}
                    <img class="config_img thumb" src="{$detail.thumb}" >
                    {/if}
                </div>
            </div>


            <div  class="form-group" >
                <label class="col-sm-1 control-label">简介:</label>
                <div class="col-sm-8">
                    <textarea name="desc" class="layui-textarea">{$detail.desc}</textarea>
                </div>
            </div>

            <!--图文模型&单页模型-->
            <div class="form-group" >
                    <label class="col-sm-1 control-label">*内容:</label>
                    <div class="col-sm-8">
                        <textarea id="content" >{$detail.content}</textarea>
                    </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label">发布日期:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" id="test" name="Wdate" placeholder="发布日期" value="{$detail.Wdate}">
                </div>

                <label class="col-sm-1 control-label">作者:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" name="author" placeholder="作者" value="{$detail.author}">
                </div>

                <label class="col-sm-1 control-label">来源:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" name="source" placeholder="来源" value="{$detail.source}">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label">排序:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" name="sort" placeholder="排序" value="{$detail.sort}">
                </div>

                <label class="col-sm-1 control-label">状态:</label>
                <div class="col-sm-2">
                    <select name="status">
                        {volist name="enable_status" id="vo"}
                        <option value="{$key}" {if condition="$detail['status'] eq $key"} selected {/if} >{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <input type="hidden" name="id" value="{$detail.id}">
            <div class="assistant_button add_button">
                <a type="button" class="layui-btn layui-btn-primary js_quit" href="{:URL('admin/News/index')}" >取消</a>
                <!--        <button type="button" class="btn btn-primary btn-sm js_add" _event="add" data-id="0" data-name="">保存</button>-->
                <a type="button" class="layui-btn js_add" id="newsave">保存</a>
            </div>
        </form>
    </div>


<script>

    var newModal = new yii.modal();
    //文件页面
    $("#upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data:{
                type:'detail'
            }
        });
    });

    newModal.on("upload",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images = $(this).attr('src');
            return false
        })
        $(newModal.getid()).hide();
        //$(".modal-backdrop").remove();
        //$('#nowMainProjectDataForm').modal('hide');
        $(newModal.getid()).find(".modal").hide();
        $("#thumb").val(images);
        $(".config_img").attr("src",images)
    });

    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form', 'jquery', 'layer', 'laydate','tinymce'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var tinymce = layui.tinymce;
        laydate.render({
            elem: '#test'
            //,type: 'date' //默认，可不填
        });

        //获取分类
        form.on('select(community_id)', function (data) {
            //触发联动
            var id = data.value;
            $.ajax({
                type: 'post',
                url: "{:URL('common/Common/findClassify')}",
                data: {id: id},
                dataType: 'JSON',
                success: function (res) {
                    var data = res.data;
                    //生成楼栋信息
                    var html = '<option value="">请选择分类</option>';
                    $.each(data, function(e,v){
                        html +='<option value="'+v.id+'">'+v.name+'</option>';
                    });
                    $('select[name="classify_id"]').html(html);
                    form.render('select');
                },
                error: function (res) {
                }
            });
        });
        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        },(opt, edit) => {

        });


        $("#newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            data.push({name: "content", value: content});
            $.ajax({
                type: 'post',
                url: "{:URL('admin/News/doNews')}",
                data: data,
                dataType: 'JSON',
                success: function (res) {
                    if (res.code != 0) {
                        layer.alert(res.msg);
                    } else {
                        window.location.href = "{:URL('admin/News/index')}"
                    }
                },
                error: function (res) {

                }
            });
        })


        form.render('select');

    });

</script>

</body>
</html>